<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    title="执行监听 添加/修改"
    width="450px"
  >
    <el-form ref="formData" :size="formSize" :model="formData" label-width="100px">
      <el-form-item label="事件：" prop="event">
        <el-select v-model="formData.event" style="width: 100%;">
          <el-option v-for="(item, index) in eventOpt" :key="index" :value="item.value" :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="类型：" prop="type">
        <el-select v-model="formData.type" style="width: 100%;">
          <el-option v-for="(item, index) in typeOpt" :key="index" :value="item.value" :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="值：" prop="value">
        <el-input v-model="formData.value" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="success" @click="saveBtn">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { executionListenerOpt } from '../../../utils/options'
export default {
  name: 'ExecutionListener',
  props: {
    formSize: {
      type: String,
      default: 'mini'
    }
  },
  data() {
    return {
      dialogVisible: false,
      formData: {
        event: null,
        type: null,
        value: null
      },
      typeOpt: executionListenerOpt.typeOpt,
      eventOpt: executionListenerOpt.eventOpt,
      oldFormData: {}
    }
  },
  methods: {
    showDialog(row) {
      this.dialogVisible = true
      this.oldFormData = {}
      if (row) {
        this.oldFormData = Object.assign({}, row)
        this.formData = Object.assign({}, row)
      } else {
        this.$nextTick(() => {
          this.$refs.formData.resetFields()
        })
      }
    },
    hiddenDialog() {
      this.dialogVisible = false
    },
    saveBtn() {
      this.$emit('saveListener', this.formData, this.oldFormData,
        'executionListener', 'flowable:ExecutionListener', 'ExecutionListenerDialog')
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/.el-dialog__body {
  padding: 20px 20px 0 20px;
}
</style>
